package leecode

func romanToInt(s string) (result int) {
	var hashMap = map[byte]int{'I': 1, 'V': 5, 'X': 10, 'L': 50, 'C': 100, 'D': 500, 'M': 1000}
	length := len(s)
	for index := range s {
		value := hashMap[s[index]]
		if index < length-1 && value < hashMap[s[index+1]] {
			result -= value
		} else {
			result += value
		}
	}
	return
}
